package com.sgy.netty.business;

import com.alibaba.fastjson.JSON;
import com.sgy.common.ApiResult;
import com.sgy.common.ImRequest;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import io.netty.util.concurrent.GlobalEventExecutor;

public class UserProc {
    //新用户连接
    public ApiResult getLineNum(ChannelHandlerContext ctx, ImRequest request){
        ApiResult result = ApiResult.success();
        result.setUrl(request.getUrl());
        result.setData(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE).size());
        ctx.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(result)));
        return  result;
    }
}
